#include "Server.h"

Server::Server( boost::asio::io_service& ios, short port ) : m_io_service(ios),
	m_acceptor(ios, tcp::endpoint(tcp::v4(), port))
{
	start_accept();
}

void Server::start_accept()
{
	ClientSession* new_session = new ClientSession(m_io_service);
	m_acceptor.async_accept(new_session->socket(),
		boost::bind(&Server::handle_accept, this, new_session,
		boost::asio::placeholders::error));
}

void Server::handle_accept( ClientSession* new_session, const boost::system::error_code& error )
{
	if (!error) {
		new_session->start();
	} else {
		delete new_session;
	}

	start_accept();
}
